﻿using System;
using System.Collections.Generic;
using System.Text;
using Roslyn.Compilers.CSharp;

namespace BITS.PreCompiler.CSharp.Syntax.Extensions
{
    public static class BaseSyntaxNodeExtension
    {
        /// <summary>
        /// Toes the strings.
        /// </summary>
        /// <typeparam name="TSyntaxNode">The type of the syntax node.</typeparam>
        /// <param name="this">The @this.</param>
        /// <returns></returns>
        public static IEnumerable<string> AsStrings<TSyntaxNode>(this IEnumerable<IBaseSyntaxNode<TSyntaxNode>> @this)
            where TSyntaxNode : SyntaxNode
        {
            foreach (var baseSyntaxNode in @this)
                yield return baseSyntaxNode.ToString();
        }

        /// <summary>
        /// Returns a <see cref="string"/> that represents this instance.
        /// </summary>
        /// <typeparam name="TSyntaxNode">The type of the syntax node.</typeparam>
        /// <param name="this">The @this.</param>
        /// <returns>
        /// A <see cref="string"/> that represents this instance.
        /// </returns>
        public static String AsString<TSyntaxNode>(this IEnumerable<IBaseSyntaxNode<TSyntaxNode>> @this)
            where TSyntaxNode : SyntaxNode
        {
            var sb = new StringBuilder();

            foreach (var s in @this.AsStrings())
                sb.AppendLine(s);

            return sb.ToString();
        }
    }
}
